package com.rohoo.user.dao.impl;

import org.springframework.dao.EmptyResultDataAccessException;

import com.rohoo.framework.dao.BaseDAO;
import com.rohoo.framework.dao.DAORowMapper;
import com.rohoo.user.bo.LoginUser;
import com.rohoo.user.dao.SloginDAO;

public class SloginDAOImpl extends BaseDAO implements SloginDAO {
	
	public String getPwd(String loginname) {
		String sql="select loginpwd from user where 1=1 and username='" + 
			loginname +"'";
		String result;
		try {
			result = (String)this.getJdbcTemplate().queryForObject(sql, String.class);
		} catch (EmptyResultDataAccessException ex) {
			result = "";
		}
		return result;
	}
	
	public int getUserId(String loginname) {
		String sql="select userid from username where 1=1 and username='"+
			loginname + "'";
		Integer result;
		try {
			result = getJdbcTemplate().queryForInt(sql);
		} catch (EmptyResultDataAccessException ex) {
			result = 0;
		}
		return result;
	}
	
	public LoginUser getLoginUser(int userid) throws Exception {
		LoginUser loginUser = new LoginUser();
		try {
			String sql = "select t.* from username t where t.userid="+userid;
			loginUser = (LoginUser)this.getJdbcTemplate().queryForObject(sql, new DAORowMapper(LoginUser.class));
		} catch (Exception e) {
			loginUser = null;
		}
		return loginUser;
	}
	
}
